package com.web;


import com.DisplayChatters;
import com.domain.Chatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/displayUsers")
public class DisplayUsersController {
    @Autowired
    private DisplayChatters displayChatters;

    @RequestMapping("/displayUsers")
    public ModelAndView displayUsers(HttpServletRequest request, HttpServletResponse response) {
        List<Chatter> userList = new ArrayList<Chatter>();
        try {
            userList = displayChatters.getUsers();
        } catch (ClassNotFoundException | SQLException | IOException | NamingException e) {
            e.printStackTrace();
        }
        return new ModelAndView("displayUsers", "userList", userList);
    }
}
